package ter.find.pattern.gui;

import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeListener;

import ter.find.pattern.ModelCharge;
import ter.find.pattern.ModelMotif;

import com.ter.Form;
public class ControlPanel extends JPanel{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JSpinner spinSupport=new JSpinner();
	private JSlider sliderSupport=new JSlider();
	
	private JLabel labeltext=new JLabel("Support");
	private JPanel panelSup=new JPanel();
	private ModelMotif model;
	
	public ControlPanel() {
		// TODO Auto-generated constructor stub
		//model=m;
		setVisible(true);
		//this.setLayout(null);
		this.setSize(200, 100);
		this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
		
		//setLayout(null);
		panelSup.setBounds(20,20,300,100);
		//panelSup.setLayout(null);
		panelSup.setBorder(new TitledBorder("Définir Support"));
		labeltext.setBounds(5,20,100,20);
		panelSup.add(labeltext);
		spinSupport.setBounds(130,20,150,20);
		spinSupport.setSize(100, 20);
		panelSup.add(spinSupport);
		sliderSupport.setBounds(250,20,150,40);
		sliderSupport.setMajorTickSpacing(20);
		sliderSupport.setMinorTickSpacing(5);
		sliderSupport.setPaintTicks(true);
		sliderSupport.setPaintLabels(true);
		panelSup.add(sliderSupport);
		//panelSup.setLayout(new BoxLayout(panelSup, BoxLayout.PAGE_AXIS));
		add(panelSup);
		
		
	}
	public void setValueModel(){
		model.setMinSup(this.getSliderSupport());
	}
	
	public int getSpinSupport(){
		System.out.println(spinSupport.getValue());
		return (int) spinSupport.getValue();
	}
	
	public int getSliderSupport(){
		return sliderSupport.getValue();
	}
	
	//Methode qui met à jour les valeurs dans view
	public void setValue(int v){
		spinSupport.setValue(v);
		sliderSupport.setValue(v);
	}
	
	//set Value prend les valeurs dans modèle et change les valeurs dans les champs
	
	
	public void addSSListener(ChangeListener act){
		sliderSupport.addChangeListener(act);
		spinSupport.addChangeListener(act);
	}
	
	
	public static void main(String[] args) {
		JFrame frame = new JFrame("Control");
		frame.addWindowListener(new WindowAdapter() {

			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		
		new ModelMotif();
		new ModelCharge();
		new Form();
		ControlPanel c=new ControlPanel();
		new ChangeForm();
		//Gui g=new Gui(c, mp,cp,f);
		//InterfaceEngine i=new InterfaceEngine(m,g,c);
		frame.getContentPane().add(c,
				BorderLayout.CENTER);
		frame.setSize(500, 300);
		frame.setVisible(true);
		
		
        
    }

}
